<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>payment</title>
    <link rel="stylesheet" href="../../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <div class="layui-form-item">
            <label class="layui-form-label">id:</label>
            <div class="layui-input-inline">
                <input type="text" name="idd" placeholder="请输入" autocomplete="off" class="layui-input" id="idd" value="1">
            </div>
            <div class="layui-input-inline">
                <button type="submit" class="layui-btn layui-btn-primary" lay-submit  lay-filter="data-search-s1"><i class="layui-icon"></i> 搜 索</button>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">部门:</label>
            <div class="layui-input-inline">
                <div class="layui-form" lay-filter="myDiv">
                    <select name="" id="type" lay-filter="mySelect">
                        <option value="1">打杂</option>
                        <option value="2">清洁工</option>
                        <option value="3">食堂用工</option>
                    </select>
                </div>
            </div>
            <div class="layui-input-inline">
                <button type="submit" class="layui-btn layui-btn-primary" lay-submit lay-filter="data-search-s2"><i
                        class="layui-icon"></i> 搜 索
                </button>
            </div>
        </div>

        <div class="layui-btn-container">
            <button class="layui-btn layui-btn-sm data-add-btn"> 添加临时工 </button>
        </div>
        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-xs data-count-sel" lay-event="sel">辞职</a>
        </script>

    </div>
</div>

<script src="../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="../../js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script>
    layui.use(['table', 'form'], function () {
        //开始使用

        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            layuimini = layui.layuimini;



        //加载所有临时工
        table.render({
            elem: '#currentTableId',
            url: 'http://localhost:8080/department/selectTWorker',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                {field: 'tid', width: 80, title: 'ID', sort: true},
                {field: 'tname', width: 100, title: '姓名'},
                {field: 'tsex', width: 100, title: '年龄'},
                {field: 'tage', width: 100, title: '地址'},
                {field: 'trole', width: 100, title: '在职状态'},
                {field: 'taddress', width: 100, title: '地址'},
                {field: 'pronames', width: 100, title: '部门名称'},
                {field: 'tctime', width: 100, title: '创建时间'},
                {title: '操作', width: 150, templet: '#currentTableBar', fixed: "right", align: "center"}
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: true
        });


        //辞职
        table.on('tool(currentTableFilter)', function (obj) {
            if (obj.event === 'sel') {
                var data = obj.data;  //得到修改后的值
                $.ajax({
                    url:'http://localhost:8080/department/resignid?id='+data['tid'],
                    method:'get',
                    data:data.field,
                    dataType:'JSON',
                    success:function(res){
                        if(res.code==='0'){
                            parent.closeIframe("辞职成功!");
                        }
                        else
                            alert(res['msg']);
                    },
                    error: function(XMLHttpRequest, textStatus, errorThrown) {
                        alert("辞职失败!");
                    }
                }) ;
                table.reload('currentTableId', {
                }, 'data');
                return false;
            }
        });

        // 监听搜索操作
        form.on('submit(data-search-s2)', function (data) {
            var field = data.field;

            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    did: $('#type').val(),
                }//这里传参  向后台
                , url: 'http://localhost:8080/department/selectTWorkerByDepartment'
                , method: 'get'
            }, 'data');

            return false;
        });

        // 监听搜索操作
        form.on('submit(data-search-s1)', function (data) {
            var field = data.field;

            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    id: $('#idd').val(),
                }//这里传参  向后台
                , url: 'http://localhost:8080/department/selectTWorkerByid'
                , method: 'get'
            }, 'data');

            return false;
        });


        // 监听添加操作
        $(".data-add-btn").on("click", function () {

            var index = layer.open({
                title: '添加临时工',
                type: 2,
                shade: 0.2,
                maxmin: true,
                shadeClose: true,
                area: ['100%', '100%'],
                content: './operation/add_twork.html',
            });
            $(window).on("resize", function () {
                layer.full(index);
            });

            return false;
        });


    });
</script>
</body>
</html>